﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using LaunchMeNot.Core;
using LaunchMeNot.DAL;
using NUnit.Framework;

namespace LaunchMeNot.Tests.Core
{
    [TestFixture]
    public class ShortcutTests
    {
        List<IStartupEntry> shortcuts;
        DirectoryStore cuStore;
        [SetUp]
        protected void SetUp() {
            shortcuts = new List<IStartupEntry>();
            for(int i = 0; i < 5; i++) {
                string filename = Path.GetRandomFileName();
                ShellShortcut shortcut = new ShellShortcut(filename, "C:\\dummy.txt", string.Empty, Path.GetFileNameWithoutExtension(filename) + ".lnk");
                shortcuts.Add(shortcut);
            }
            cuStore = new DirectoryStore(LaunchMeNotBLL.GetPath(StartupEntryType.CurrentUserStartup));
        }

        [Test]
        public void CanAddCurrentUserShortcuts()
        //public void Test(string fileName, string expectedBundleName, string expectedCultureName)
        {
            cuStore.AddStartupEntries(shortcuts);
            var shortcutsFromStore = cuStore.GetStartupEntries();
            foreach(var loadedShortcut in shortcutsFromStore) {
                Assert.Contains(loadedShortcut, shortcuts);
            }

            /*   CultureInfo cultureInfo = ResxResourceImporter.GetCultureFromFileName(fileName, out bundleName);
            if (cultureInfo != null) {
                result = expectedBundleName.Equals(bundleName) && expectedCultureName.Equals(cultureInfo.Name);
            } else {
                result = expectedBundleName.Equals(bundleName) && expectedCultureName == null;
            }
            Assert.True(result);*/
        }

        [Test]
        public void CanDeleteCurrentUserShortcuts() {
            foreach(var shortcut in shortcuts) {
                cuStore.DeleteStartupEntry(shortcut);
            }
            var shortcutsFromStore = cuStore.GetStartupEntries();
            foreach(var addedShortcut in shortcutsFromStore) {
                Assert.False(!shortcutsFromStore.Contains(addedShortcut));
            }
        }

        [TearDown]
        public void TearDown() {
            shortcuts.ForEach(s => {
                                  try {
                                      cuStore.DeleteStartupEntry(s);
                                  } catch {
                                  }
                              });
        }
    }
}
